//
//  LWPopupAnimationSheetStyle.swift
//  LWPopupViewController-Swift
//
//  Created by 钟志远 on 2021/1/6.
//

import Foundation
import UIKit

public class LWPopupAnimationSheetStyle: LWPopupAnimationContainer {
    override func setup() {
//        self.showAnimation = ^(LWPopupViewController * _Nonnull pop, void(^completeBlock)(BOOL)) {
//            pop.view.alpha = 0;
//            [pop.contenteView setNeedsUpdateConstraints];
//            [pop.contenteView updateConstraints];
//            NSLog(@"%@",pop.contenteView);
//            CGRect contentViewRect = pop.contenteView.frame;
//            pop.contenteView.transform = CGAffineTransformMakeTranslation(0, contentViewRect.size.height);
//            [UIView animateWithDuration:0.2 animations:^{
//                pop.view.alpha = 1;
//                pop.contenteView.transform = CGAffineTransformMakeTranslation(0, 0);
//            } completion:^(BOOL finished) {
//                if (completeBlock) {
//                    completeBlock(finished);
//                }
//            }];
//        };
        showAnimation = { pop , completeBlock in
            pop.view.alpha = 0
            pop.contentView?.setNeedsUpdateConstraints()
            pop.contentView?.updateConstraints()
            guard let contentViewRect = pop.contentView?.frame else {
                return
            }
            pop.contentView?.transform = CGAffineTransform.init(translationX: 0, y: contentViewRect.size.height)
            UIView.animate(withDuration: 0.3) {[unowned pop] in
                pop.view.alpha = 1
                pop.contentView?.transform = CGAffineTransform.init(translationX: 0, y: 0)
            } completion: { (b) in
               completeBlock?(b)
            }
        }
//
//        self.hiddenAnimation = ^(LWPopupViewController * _Nonnull pop, void(^completeBlock)(BOOL)) {
//            CGRect contentViewRect = pop.contenteView.frame;
//            [UIView animateWithDuration:0.2 animations:^{
//                pop.view.alpha = 0;
//                pop.contenteView.transform = CGAffineTransformMakeTranslation(0, contentViewRect.size.height);
//            } completion:^(BOOL finished) {
//                if (completeBlock) {
//                    completeBlock(finished);
//                }
//            }];
//        };


        hiddenAnimation = { pop , completeBlock in
            guard let contentViewRect = pop.contentView?.frame else {
                return
            }
            UIView.animate(withDuration: 0.3) {[unowned pop] in
                pop.view.alpha = 0
                pop.contentView?.transform = CGAffineTransform.init(translationX: 0, y: contentViewRect.size.height)
            } completion: { (b) in
               completeBlock?(b)
            }
        }

    }
}
